<template>
  <div class="app-container">
    <div class="filter-container default-box">
      <span>ID：</span>
      <el-input v-model="listQuery.account" placeholder="请输入ID" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
      <span style="padding-left: 100px">票号：</span>
      <el-input v-model="listQuery.account" placeholder="请输入票号" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-button class="filter-item" type="primary" icon="el-icon-search" style="margin-left:100px" round @click="handleFilter">
        查询
      </el-button>
      <el-button class="filter-item" icon="el-icon-refresh-right" round @click="handlReset">
        重置
      </el-button>
    </div>
    <div class="default-box">
      <el-table
        :key="tableKey"
        v-loading="listLoading"
        :data="list"
        fit
        highlight-current-row
        style="width: 100%;"
      >
        <el-table-column label="用户账号" show-overflow-tooltip>
          <template>
            <span>123456</span>
          </template>
        </el-table-column>
        <el-table-column label="用户昵称" show-overflow-tooltip>
          <template>
            <span>123456</span>
          </template>
        </el-table-column>
        <el-table-column label="用户等级">
          <template>
            <span>
              淘粉
            </span>
          </template>
        </el-table-column>
        <el-table-column label="票号">
          <template>
            <span>123456</span>
          </template>
        </el-table-column>
        <el-table-column label="是否中奖">
          <template>
            <span class="danger-color">未中奖</span>
            <span class="success-color">中奖</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" class-name="small-padding fixed-width">
          <template>
            <el-button type="primary" round @click="handleWinPrize">设置中奖</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    </div>
  </div>
</template>

<script>
import { fetchList } from '@/api/article'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
export default {
  name: 'Recycle',
  components: { Pagination },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 10,
        account: ''
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      fetchList(this.listQuery).then(response => {
        this.list = response.data.items
        this.total = response.data.total
        setTimeout(() => {
          this.listLoading = false
        }, 1.5 * 1000)
      })
    },
    // 重置
    handlReset() {
      this.listQuery.account = ''
    },
    // 搜索
    handleFilter() {
      this.getList()
    },
    // 设置中奖
    handleWinPrize(row, index) {
      this.$confirm('确定要指定该票号中奖吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        center: true,
        customClass: 'text-center'
      }).then(() => {
        this.$notify({
          title: '成功',
          message: '设置成功',
          type: 'success',
          duration: 2000
        })
        // this.$message({
        //   type: 'success',
        //   message: '删除成功!'
        // })
      }).catch(() => {

      })
    }
  }
}
</script>
<style scoped>
  [class^=el-icon-], [class*=" el-icon-"]{
    font-size: 16px;
  }
  .small-padding i{
    margin-right: 12px;
  }
  .small-padding i:last-child{
    margin-right: 0px;
  }
</style>
